#ifndef RTMPSINK_H
#define RTMPSINK_H

#ifdef __cplusplus
extern "C" {
#endif

enum RTMP_PayloadType {
	PAYLOADTYPE_START,
	PAYLOADTYPE_VIDEO = PAYLOADTYPE_START,
	PAYLOADTYPE_AUDIO,
	PAYLOADTYPE_END,
};

enum RTMP_CodecType {
	CODECTYPE_START,
	/*video*/
	CODECTYPE_VIDEO_START = CODECTYPE_START,
	CODECTYPE_VIDEO_H264 = CODECTYPE_VIDEO_START,
	CODECTYPE_VIDEO_END,
	/*audio*/
	CODECTYPE_AUDIO_START = CODECTYPE_VIDEO_END,
	CODECTYPE_AUDIO_AAC = CODECTYPE_AUDIO_START,
	CODECTYPE_AUDIO_END,
	CODECTYPE_END = CODECTYPE_AUDIO_END,
};

enum RTMP_Parameter {
	PARAMETER_START,
	PARAMETER_TIMESTAMP = PARAMETER_START,
	/*video*/
	PARAMETER_VIDEO_START,
	PARAMETER_VIDEO_FRAMERATE = PARAMETER_VIDEO_START,
	PARAMETER_VIDEO_H264_START,
	PARAMETER_VIDEO_H264_SPS = PARAMETER_VIDEO_H264_START,
	PARAMETER_VIDEO_H264_PPS,
	PARAMETER_VIDEO_H264_STARTCODE,
	PARAMETER_VIDEO_H264_END,
	PARAMETER_VIDEO_END = PARAMETER_VIDEO_H264_END,
	/*audio*/
	PARAMETER_AUDIO_START = PARAMETER_VIDEO_END,
	PARAMETER_AUDIO_SAMPLERATE = PARAMETER_AUDIO_START,
	PARAMETER_AUDIO_CHANNELCONFIG,
	PARAMETER_AUDIO_SAMPLEBITS,
	PARAMETER_AUDIO_AAC_START,
	PARAMETER_AUDIO_AAC_AUDIOSPECIFICCONFIG = PARAMETER_AUDIO_AAC_START,
	PARAMETER_AUDIO_AAC_END,
	PARAMETER_AUDIO_END = PARAMETER_AUDIO_AAC_END,
	PARAMETER_END = PARAMETER_AUDIO_END,
};

#define RTMP_FLAG_SINGLE_NALU 0x01
#define RTMP_FLAG_INCLUDE_START_CODE (0x01 << 1)
#define RTMP_FLAG_WITH_EXTRA (0x01 << 2)
#define RTMP_FLAG_INCLUDE_TIMESTAMP (0x01 << 3)
#define RTMP_FLAG_PAYLOAD_AUDIO (0x01 << 4)

/*
 * description: create a RTMP sink
 * params:
 *	url:
 *		url to push RTMP stream
 *	video_codec_type:
 *		valid value of RTMP_CodecType
 *	audio_codec_type:
 *		valid value of RTMP_CodecType
 * return:
 *	pointer to RTMPSink on success, NULL on error
 */
void * RTMPSink_Create(const char *url, int video_codec_type, int audio_codec_type);

/*
 * description: destroy a RTMP sink
 * params:
 *	rtmp_sink:
 *		pointer to RTMPSink
 * return:
 *	0 on success, proper errno on error
 */
int RTMPSink_Destroy(void **rtmp_sink);

/*
 * description: set parameter to a RTMP sink
 * params:
 *	rtmp_sink:
 *		pointer to RTMPSink
 *	parameter_type:
 *		valid value of RTMP_Parameter
 *	parameter:
 *		pointer to parameter value
 *	parameter_size:
 *		size of parameter value
 * return:
 *	0 on success, proper errno on error
 */
int RTMPSink_SetParameter(void *rtmp_sink, int parameter_type, const void *parameter, unsigned int parameter_size);

/*
 * description: get parameter of a RTMP sink
 * params:
 *	rtmp_sink:
 *		pointer to RTMPSink
 *	parameter_type:
 *		valid value of RTMP_Parameter
 *	parameter:
 *		pointer to parameter value to store parameter
 *	parameter_size:
 *		size of parameter store space
 * return:
 *	0 on success, proper errno on error
 */
int RTMPSink_GetParameter(void *rtmp_sink, int parameter_type, void *parameter, unsigned int *parameter_size);

/*
 * description: write payload to a RTMP sink
 * params:
 *	rtmp_sink:
 *		pointer to RTMPSink
 *	payload:
 *		pointer of payload data
 *	payload_size:
 *		size of payload data
 *	parameter_size:
 *		size of parameter value
 *	flags:
 *		or value of
 *			RTMP_FLAG_SINGLE_NALU
 *			RTMP_FLAG_INCLUDE_START_CODE
 *			RTMP_FLAG_WITH_EXTRA
 *			RTMP_FLAG_INCLUDE_TIMESTAMP
 * return:
 *	0 on success, proper errno on error
 */
int RTMPSink_Write(void *rtmp_sink, void *payload, unsigned int payload_size, int flags, void *extra);

/*
 * description: get library version of RTMP sink
 * return:
 *	version number of library
 */
int RTMPSink_GetVersion();

#ifdef __cplusplus
}
#endif

#endif /* RTMPSINK_H */
